package com.spring.quickstart.controller.demo;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.spring.quickstart.entity.Student;

@Controller
public class SpringELAction {

	@Value("#{systemProperties['companyAddress']}")
	//@Value("${companyAddress}")
	public String companyAddress;

	@Autowired
	private Student student;

	//http://127.0.0.1:8080/demo/showSpEL.json
	@RequestMapping(value = "/demo/showSpEL", method = RequestMethod.GET, produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public Map<String, Object> showSpEL(HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<>();

		resultMap.put("stuId", student.getStuId());
		resultMap.put("stuName", student.getStuName());
		resultMap.put("companyAddress", companyAddress);

		return resultMap;
	}
}
